ccR.Add_Rotation(
		4,
		"CDM_Druid_Restoration",
		"cdMichealB's fantastic healing.",
		"CDM_Druid_Restoration_Talents",
		"CDM_Druid_Restoration_Abilities",
		"CDM_Druid_Restoration_Features",
		"CMD_Druid_Restoration_Setup"
)
	--Kargath Bladefist
	local KA_IMPALE = 159113 
	--The Butcher
	local BU_CLEAVE = 156157
	local BU_GUSHING_WOUNDS = 156152

	--Tectus
	local TE_TECTONIC_UPHEAVAL = 162475

	--Brackenspore
	local BR_INFESTING_SPORES = 163242
	local BR_LIVING_SPORES = 159463
	local BR_DECAY = 160013
	local BR_NECROTIC_BREATH = 159220
	local BR_GREEN_WITHERING = 160399
	local BR_GREEN_WITHERING_FAST = 163113
	local BR_BLUE_WITHERING = 163122
	local BR_BLUE_WITHERING_FAST = 163124

	--Twin Orgron
	local OR_INTERRUPTING_SHOUT = 158102


	--Ko'ragh
	local KO_EXPEL_MAGIC_SHADOW = 162184 --Expel Magic: Shadow
	local KO_EXPEL_MAGIC_FIRE = 162185
	local KO_EXPEL_MAGIC_FROST = nil
	local KO_EXPEL_MAGIC_ARCANE = 162186
	local KO_CAUSTIC_ENERGY = 161242
	local KO_SUPPRESSION_FIELD = 161328

--Imperator Mar'gok

--Player stuff
	local WildCount = {}
	local ClusterCount = {}
	local ClusterPreCount = {}
	local GenesisCount = {}
	onlyPlayers = false
	local RejShroomFound = nil
	local foundLifeBloom = false
	local BossTarget = nil
	local TrashTarget = nil
	local LowestHP = nil
	local SecondLowestHP = nil
	local Tank1 = nil
	local Tank2 = nil
	local Tank3 = nil
	local vUnit = nil
	local RejShroom = nil
	local LifeShroom = nil
	local foundLifeBloom = nil
	local BossTarget = nil
	local TrashTarget = nil
	local f = nil
	local HighestTank = nil
	local LowestTank = nil
function CDM_Druid_Restoration()
	--ccR.PrintToChat(GetTime())
	table.wipe(WildCount)
	table.wipe(ClusterCount)
	table.wipe(ClusterPreCount)
	table.wipe(GenesisCount)
	LowestHP = "player"
	SecondLowestHP = "player"
	if not ccR.Unit.Exists(Tank1) or not ccR.Unit.Is.Tank(Tank1) then
		Tank1 = nil
	end
	if not ccR.Unit.Exists(Tank2) or not ccR.Unit.Is.Tank(Tank2) then
		Tank2 = nil
	end
	if not ccR.Unit.Exists(Tank3) or not ccR.Unit.Is.Tank(Tank3) then
		Tank3 = nil
	end
	vUnit = nil
	RejShroom = nil
	LifeShroom = nil
	foundLifeBloom = false
	BossTarget = nil
	TrashTarget = nil
	HighestTank = nil
	LowestTank = nil
	onlyPlayers = ccR.Var("OnlyPlayers")
	--if RejShroom = ""
--End declarations
	
	if ccR.Player.Is.CastingSpell(WRATH) and ClearCast() and ccR.Unit.Health(LowestHP) < 96 then SpellStopCasting() end

	--Tank1 = ""  --overide
	--Tank2 = ""  --overide2

	for i = 1, # ccR_Friendly do 
		local vUnit = ccR_Friendly[i]
		table.wipe(ClusterPreCount)
		if ValidToHeal(vUnit, true) and (ccR.Unit.Is.APlayer(vUnit) or onlyPlayers == false) and ccR.Unit.Distance(vUnit, "player") <= 60 then
			if ccR.Unit.Has.MyBuff(vUnit, LIFEBLOOM) then
				foundLifeBloom = true
			end
			--Tanks
			if ccR.Unit.Is.APlayer(vUnit) and (Tank1 == nil or Tank2 == nil or Tank3 == nil) then
				if ccR.Unit.Is.Tank(vUnit) and Tank1 == nil then
					Tank1 = vUnit
				elseif ccR.Unit.Is.Tank(vUnit) and Tank2 == nil and Tank1 ~= nil then
					Tank2 = vUnit
				elseif  ccR.Unit.Is.Tank(vUnit) and Tank3 == nil and Tank1 ~= nil and Tank2 ~= nil then
					Tank3 = vUnit
				end
			end
			if ccR.Var("HealBlueShroom") and ccR.Unit.Name(vUnit) == "Rejuvenating Mushroom" then
				RejShroom = vUnit
			end
			if ccR.Var("HealGreenShroom") and ccR.Unit.Name(vUnit) == "Living Mushroom" then
				LifeShroom = vUnit
			end
			if ValidToHeal(vUnit) 
			and not ccR.Unit.Has.Debuff(vUnit, 159220) 
			and not ((ClearCast() or ccR.Player.Has.Buff(TREE_OF_LIFE)) and ccR.Unit.Name(vUnit) == "Living Mushroom") 
			and ((ccR.Unit.Name(vUnit) == "Living Mushroom" and ccR.Var("HealGreenShroom")) or ccR.Unit.Name(vUnit) ~= "Living Mushroom") 
			and ((ccR.Unit.Name(vUnit) == "Rejuvenating Mushroom" and ccR.Var("HealBlueShroom")) or ccR.Unit.Name(vUnit) ~= "Rejuvenating Mushroom") 
			then
				--Lowest HP
				if ccR.Unit.Health(vUnit) < ccR.Unit.Health(LowestHP) then
					SecondLowestHP = LowestHP
					LowestHP = vUnit
				elseif ccR.Unit.Health(vUnit) == ccR.Unit.Health(LowestHP) then
					if UnitHealthMax(vUnit) < UnitHealthMax(LowestHP) then
						SecondLowestHP = LowestHP
						LowestHP = vUnit
					else
						SecondLowestHP = vUnit
					end
				end
				--Counts
				if (ccR.Unit.Health(vUnit) < 75 or (ccR.Unit.Has.Debuff(vUnit, 145263) and ccR.Unit.Health(vUnit) < 100 ) or ccR.Unit.Has.Debuff(vUnit, 162184)) and ccR.Unit.Distance(vUnit, "player") < 30 then
					--table.insert(WildCount, vUnit)
					WildCount[#WildCount+1] = vUnit
				end
				if Tank1 == nil and ccR.Unit.Exists("Oto The Protector") then
					Tank1 = "Oto The Protector"
				elseif Tank1 == nil and ccR.Unit.Exists("Sikari the Mistweaver") then
					Tank1 = "Sikari the Mistweaver"
				--elseif Tank1 == nil and ccR.Unit.Exists("Resilient Arcane Elemental") then
				--	Tank1 = "Resilient Arcane Elemental"
				--elseif ccR.Unit.Exists("Aeda Brightdawn") then
					--Tank1 = "Aeda Brightdawn"
				--elseif Tank1 == nil and Tank2 == nil then
					--Tank1 = "player"
				end
				--if ccR.Unit.Name(vUnit) == "Aeda Brightdawn" then
				--	Tank1 = vUnit
				--end
				for f = 1, # ccR_Friendly do
					local vvvUnit = ccR_Friendly[f]
					if ccR.Unit.Distance(vvvUnit, vUnit) <= 10 and (ccR.Unit.Is.APlayer(vvvUnit)) then
						--table.insert(ClusterPreCount, vvvUnit)
						ClusterPreCount[#ClusterPreCount+1] = vvvUnit
					end 
				end
				if (ClusterPreCount and # ClusterPreCount > # ClusterCount) or ClusterCount == nil then
					table.wipe(ClusterCount)
					for f = 1, # ccR_Friendly do
						local vvvUnit = ccR_Friendly[f]
						if ccR.Unit.Distance(vvvUnit, vUnit) <= 10 and (ccR.Unit.Is.APlayer(vvvUnit)) then
							--table.insert(ClusterCount, vvvUnit)
							ClusterCount[#ClusterCount+1] = vvvUnit
						end 
					end
				end

				--ccR.Paladin.Feature.Cure("player")
				--ccR.Paladin.Feature.Cure(vUnit)
			end
			if ccR.Unit.Health(vUnit) < 10 and (ccR.Unit.Has.MyBuff(vUnit, REJUVENATION) or ccR.Unit.Has.MyBuff(vUnit, GERMINATION)) then
				--table.insert(GenesisCount, vUnit)
				GenesisCount[#GenesisCount+1] = vUnit
			end
		end
	end

	if Tank1 and Tank2 and ccR.Unit.Health(Tank1) <= ccR.Unit.Health(Tank2) then
		LowestTank = Tank1
		HighestTank = Tank2
	elseif Tank1 and Tank2 and ccR.Unit.Health(Tank2) <= ccR.Unit.Health(Tank1) then
		LowestTank = Tank2
		HighestTank = Tank1
	elseif Tank1 then
		LowestTank = Tank1
	elseif Tank2 then
		LowestTank = Tank2
	end
	if LowestTank and LowestHP and ccR.Unit.Health(LowestHP) <= ccR.Unit.Health(LowestTank) then
		SmartHeal = LowestHP
	elseif not LowestTank and HighestTank and LowestHP and ccR.Unit.Health(LowestHP) <= ccR.Unit.Health(HighestTank) then
		SmartHeal = LowestHP
	elseif LowestTank then
		SmartHeal = LowestTank
	elseif HighestTank then 
		SmartHeal = HighestTank
	end


	if # ClusterCount > 1 then
		if SpellIsTargeting() then CastAtPosition(GetAveragePositionOfObjects(ClusterCount)); ccR.PrintToChat("Casting Targeted: " .. #ClusterCount) end
	end
	local startB, _, enableB = GetInventoryItemCooldown("player", 14)
	if ccR.Player.Mana() < 93 and enableB == 1 and startB == 0 then
		UseInventoryItem(14)
	end

	if ccR.Player.Has.Buff(TREE_OF_LIFE) and ccR.Spell.Is.Ready(NATURES_VIGIL) then
		ccR.Cast.Spell(NATURES_VIGIL)
	end
	FindThreat()
	---New Rotation
	Sooth()
	IronBark()

	Swiftmend(LowestHP, 30)
	Regrowth(LowestHP, 15)
	Swiftmend(SecondLowestHP, 30)
	Regrowth(SecondLowestHP, 15)

	AutoLifeBloom()

	Rejuvenation(RejShroom, 101)
	Germination(RejShroom, 101)

	TreeRegrowth(LowestHP, 15)
	TreeRegrowth(SecondLowestHP, 15)

	WildGrowth(5)
	Genesis()

	if (ccR.Unit.Health(LowestHP) >= 10 or ccR.Unit.Has.MyBuff(LowestHP, REJUVENATION)) and (ccR.Unit.Health(SecondLowestHP) >= 10 or ccR.Unit.Has.MyBuff(SecondLowestHP, REJUVENATION)) then
		if ccR.Unit.Health(Tank1) <= ccR.Unit.Health(Tank2) then
			Rejuvenation(Tank1, 95)
		elseif ccR.Unit.Health(Tank2) <= ccR.Unit.Health(Tank1) then
			Rejuvenation(Tank2, 95)
		end
		Rejuvenation(LowestTank, 95)
		Rejuvenation(HighestTank, 95)
	end

	Rejuvenation(LowestHP, 75)
	Rejuvenation(SecondLowestHP, 75)

	if ccR.Unit.Has.Debuff(LowestHP, BU_GUSHING_WOUNDS) then
		Rejuvenation(LowestHP, 100)
	end
	if ccR.Unit.Has.Debuff(SecondLowestHP, BU_GUSHING_WOUNDS) then
		Rejuvenation(SecondLowestHP, 100)
	end

	if (ccR.Unit.Health(LowestHP) >= 10 or ccR.Unit.Has.MyBuff(LowestHP, GERMINATION)) and (ccR.Unit.Health(SecondLowestHP) >= 10 or ccR.Unit.Has.MyBuff(SecondLowestHP, GERMINATION)) then
		if ccR.Unit.Health(Tank1) <= ccR.Unit.Health(Tank2) then
			Germination(Tank1, 85)
		elseif ccR.Unit.Health(Tank2) <= ccR.Unit.Health(Tank1) then
			Germination(Tank2, 85)
		end
		Germination(LowestTank, 85)
		Germination(HighestTank, 85)
	end

	Germination(LowestHP, 65)
	Germination(SecondLowestHP, 65)

	Regrowth(LowestTank, 75)
	Regrowth(HighestTank, 75)
	if RejShroom then
		Rejuvenation(RejShroom, 101)
		Germination(RejShroom, 101)
	end
	if RejShroom and ccR.Var("HealBlueShroom") then
		Regrowth(RejShroom, 93)
	end
	if LifeShroom and ccR.Var("HealGreenShroom") then
		Rejuvenation(LifeShroom, 101)
		Germination(LifeShroom, 101)
	end
	if LifeShroom and ccR.Var("HealGreenShroom") then
		Regrowth(LifeShroom, 93)
	end
	BlanketRejuvenation()
	BlanketGermination()

	Swiftmend(LowestHP, 20)
	Regrowth(LowestHP, 15)

	if BossTarget and ccR.Unit.TargetName(BossTarget) == ccR.Unit.Name(Tank1) then
		Regrowth(Tank1, 85)
	end
	if BossTarget and ccR.Unit.TargetName(BossTarget) == ccR.Unit.Name(Tank2) then
		Regrowth(Tank2, 85)
	end

	if TrashTarget and ccR.Unit.TargetName(TrashTarget) == ccR.Unit.Name(Tank1) then
		Regrowth(Tank1, 75)
	end
	if TrashTarget and ccR.Unit.TargetName(TrashTarget) == ccR.Unit.Name(Tank2) then
		Regrowth(Tank2, 75)
	end

	AutoWrath()


end

function ValidToHeal(tunit, ignoreRange)
	if tunit and ccR.Unit.Exists(tunit) and ccR.Unit.Is.Alive(tunit) and ccR.Unit.Is.InLineOfSight(tunit) then
		if ignoreRange then
			return true
		elseif ccR.Unit.Distance(tunit, "player") <= 40 then
			return true
		else
			return false
		end
	else
		return false
	end

end

function ClearCast()
	if ccR.Player.Has.Buff(CLEARCASTING) or (ccR.Player.Has.Buff(CLEARCASTING_CLARITY) and ccR.Player.Buff.Duration(CLEARCASTING_CLARITY) >= ccR.Spell.CastTime(REGROWTH)) or ccR.Player.Has.Buff(NATURES_SWIFTNESS) then
		return true
	else
		return false
	end
end
function FindThreat()
		for x = 1, # ccR_Enemies_In_Combat do
			local vUnit = ccR_Enemies_In_Combat[x]
			if ccR.Unit.Is.Alive(vUnit)
			
			and ccR.Unit.Is.Attackable(vUnit)
			
			
			and ccR.Unit.Is.InCombat(vUnit)
			then
				if ccR.Unit.Is.Boss(vUnit) then
					BossTarget = vUnit
				else
					TrashUnit = vUnit
				end

			end
		end
end

function AutoWrath()
	if not ccR.Player.Is.Moving() and ccR.Player.Has.Talent(DREAM_OF_CENARIUS) and ccR.Unit.Exists("target") and ccR.Target.Is.Attackable() and ccR.Player.Is.Facing("target") and ccR.Spell.Is.Ready(WRATH) and ccR.Spell.CanAttack(WRATH, "target") then
		ccR.Cast.Attack(WRATH, "target")
	else
		for x = 1, # ccR_Enemies_In_Combat do
			local vUnit = ccR_Enemies_In_Combat[x]
			if ccR.Unit.Is.Alive(vUnit)
			and ccR.Player.Is.Facing(vUnit)
			and ccR.Spell.CanAttack(WRATH, vUnit)
			and ccR.Player.Has.Talent(DREAM_OF_CENARIUS)
			and not ccR.Player.Is.Moving()
			and ccR.Unit.Is.InCombat(vUnit)
			then
				ccR.Cast.Attack(WRATH, vUnit)
			end
		end
	end
end


function Sooth()
	if ccR.Spell.Is.Ready(SOOTH) and (tLastSoothUsed == nil or (GetTime()-tLastSoothUsed >= 1.0)) then
		for x = 1, # ccR_Enemies_In_Combat do
			local vUnit = ccR_Enemies_In_Combat[x]
			if ccR.Unit.Exists(vUnit) and ccR.Unit.Distance("player", vUnit) <= 40 then
				for i = 1, 40 do 
				 	local name, _, _, _, buffType = UnitAura(vUnit, i) 
				 	if name == nil then	break else if buffType == "" then ccR.Cast.Spell(SOOTH, vUnit) tLastSoothUsed = GetTime() ccR.PrintToChat("Sooth: " .. name .. " from " .. ccR.Unit.Name(vUnit)) return end end
				end
			end
		end
	end
end


--Spell Functions
function IronBark()
	if ccR.Unit.Exists(RejShroom) and ccR.Spell.Is.Ready(IRONBARK) and not ccR.Unit.Has.Buff(RejShroom, IRONBARK) and ccR.Unit.Health(RejShroom) < 50 then
		ccR.Cast.Spell(IRONBARK, RejShroom)
	elseif Tank1 and ValidToHeal(Tank1) and ccR.Spell.Is.Ready(IRONBARK) and not ccR.Unit.Has.Buff(Tank1, IRONBARK) and (ccR.Unit.Health(Tank1) < 40 or ccR.Unit.Has.Debuff(Tank1, 159220)) then
		ccR.Cast.Spell(IRONBARK, Tank1)
	elseif Tank2 and ValidToHeal(Tank2) and ccR.Spell.Is.Ready(IRONBARK) and not ccR.Unit.Has.Buff(Tank2, IRONBARK) and (ccR.Unit.Health(Tank2) < 40 or ccR.Unit.Has.Debuff(Tank2, 159220)) then
		ccR.Cast.Spell(IRONBARK, Tank2)
	elseif not Tank2 and not Tank1 and ccR.Spell.Is.Ready(IRONBARK) and LowestHP and ValidToHeal(LowestHP) and not ccR.Unit.Has.Buff(LowestHP, IRONBARK) and ccR.Unit.Health(LowestHP) < 40 then
		ccR.Cast.Spell(IRONBARK, LowestHP)
	--elseif ccR.Unit.Exists("Oto The Protector") and ccR.Spell.Is.Ready(IRONBARK) and not ccR.Unit.Has.MyBuff("Oto The Protector", IRONBARK) and ccR.Unit.Health("Oto The Protector") < 60 then
	--	ccR.Cast.Spell(IRONBARK, "Oto The Protector")
	end
end
function AutoLifeBloom()
	if ccR.Unit.Exists(RejShroom) then
		LifeBloom(RejShroom)
	elseif (Tank1 and not ccR.Unit.Has.MyBuff(Tank1, LIFEBLOOM)) and (Tank2 == nil or (Tank2 and not ccR.Unit.Has.MyBuff(Tank2, LIFEBLOOM))) and ((Tank2 and ccR.Unit.Health(Tank1) <= ccR.Unit.Health(Tank2)) or Tank2 == nil or not ValidToHeal(Tank2, true)) then
		LifeBloom(Tank1)
	elseif (Tank2 and not ccR.Unit.Has.MyBuff(Tank2, LIFEBLOOM)) and (Tank1 == nil or (Tank1 and not ccR.Unit.Has.MyBuff(Tank1, LIFEBLOOM))) and ((Tank1 and ccR.Unit.Health(Tank2) < ccR.Unit.Health(Tank1)) or Tank1 == nil or not ValidToHeal(Tank1, true)) then
		LifeBloom(Tank2)
	elseif not Tank1 and not Tank2 and not ccR.Unit.Exists(RejShroom) or foundLifeBloom == false then
		LifeBloom("player")
	end
end

function LifeBloom(runit)
	if runit and ccR.Unit.Exists(runit) and ccR.Spell.Is.Ready(LIFEBLOOM) and ValidToHeal(runit) and not ccR.Unit.Has.MyBuff(runit, LIFEBLOOM) then
		ccR.Cast.Spell(LIFEBLOOM, runit)
	end
end
function Genesis()
	if GenesisCount and ccR.Spell.Is.Ready(GENESIS) and # GenesisCount >= 1 then
		ccR.Cast.Spell(GENESIS, "player")
		ccR.PrintToChat("Casting Genesis: " .. #GenesisCount)
	end
end
function WildGrowth(rcount)
	if WildCount and ccR.Spell.Is.Ready(WILD_GROWTH) and # WildCount >= rcount then
		ccR.Cast.Spell(WILD_GROWTH, "player")
		ccR.PrintToChat("Casting Wild Growth: " .. #WildCount)
	end
end
function NaturesSwiftness()
	if ccR.Spell.Is.Ready(NATURES_SWIFTNESS) and not ClearCast() then
		ccR.Cast.Spell(NATURES_SWIFTNESS)
	end
end

function Rejuvenation(runit, rhealth, rmana)
	if ccR.Spell.Is.Ready(REJUVENATION) and ccR.Unit.Health(runit) < rhealth and ValidToHeal(runit) and (not ccR.Unit.Has.MyBuff(runit, REJUVENATION) or ccR.Unit.MyBuffDuration(runit, REJUVENATION, "<", 4.5)) then
		ccR.Cast.Spell(REJUVENATION, runit)
	end
end
function Germination(runit, rhealth, rmana)
	if ccR.Player.Has.Talent(GERMINATION_TALENT) and ccR.Spell.Is.Ready(REJUVENATION) and ValidToHeal(runit) and ValidToHeal(runit) and ccR.Unit.Has.MyBuff(runit, REJUVENATION) and (not ccR.Unit.Has.MyBuff(runit, GERMINATION) or ccR.Unit.MyBuffDuration(runit, GERMINATION, "<", 4.5)) and ccR.Unit.Health(runit) < rhealth then
		ccR.Cast.Spell(REJUVENATION, runit)
	end
end
function Swiftmend(runit, rhealth, rmana)
	if ccR.Spell.Is.Ready(SWIFTMEND, true) and ValidToHeal(runit) and (ccR.Unit.Health(runit) < rhealth or not ccR.Player.Has.Buff(HARMONY)) and not ccR.Unit.Has.Debuff(runit, 159220) and (ccR.Unit.Has.MyBuff(runit, REJUVENATION) or ccR.Unit.Has.MyBuff(runit, REGROWTH)) then
		ccR.Cast.Spell(SWIFTMEND, runit)
	end
end
function Regrowth(runit, rhealth, rmana)
	if (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS) or ccR.Player.Has.Buff(TREE_OF_LIFE)) and ValidToHeal(runit) and runit and ccR.Spell.Is.Ready(REGROWTH) and not ccR.Unit.Has.Debuff(runit, 159220) and (ccR.Unit.Health(runit) < rhealth or (ccR.Unit.Health(runit) <= 93 and ClearCast()) or (ccR.Unit.Has.Debuff(runit, 145263) and ccR.Unit.Health(runit) < 100 )) then
		NaturesSwiftness()
		ccR.Cast.Spell(REGROWTH, runit)
	end
end
function TreeRegrowth(runit, rhealth, rmana)
	if (not ccR.Player.Is.Moving() or ccR.Player.Has.Buff(NATURES_SWIFTNESS) or ccR.Player.Has.Buff(TREE_OF_LIFE)) and ValidToHeal(runit) and runit and ccR.Spell.Is.Ready(REGROWTH) and not ccR.Unit.Has.Debuff(runit, 159220) and (ccR.Unit.Health(runit) < 20 or (ccR.Unit.Health(runit) <= rhealth and ccR.Player.Has.Buff(TREE_OF_LIFE)) or (ClearCast() and ccR.Unit.Health(runit) <= 96 ) or (ccR.Unit.Has.Debuff(runit, 145263) and ccR.Unit.Health(runit) < 100 )) then
		NaturesSwiftness()
		ccR.Cast.Spell(REGROWTH, runit)
	end
end
function BlanketRejuvenation(rhealth, treehealth, rmana)
	if ccR.Spell.Is.Ready(REJUVENATION) then
		for i = 1, # ccR_Friendly do 
			local vUnit = ccR_Friendly[i]
			if ccR.Unit.Exists(vUnit) and ccR.Unit.Is.Alive(vUnit) and ValidToHeal(vUnit) and (ccR.Unit.Is.APlayer(vUnit) or onlyPlayers == false) and ccR.Unit.Is.InLineOfSight(vUnit) and ccR.Unit.Distance(vUnit, "player") <= 40 then
				

				if ccR.Unit.Distance(vUnit, "player") <= 40 and (not ccR.Unit.Has.MyBuff(vUnit, REJUVENATION)) and (ccR.Unit.Health(vUnit) < 90 or (ccR.Player.Has.Buff(TREE_OF_LIFE) and ccR.Unit.Health(vUnit) < 90 ) or ccR.Unit.Has.Debuff(vUnit, 162184) ) then
					ccR.Cast.Spell(REJUVENATION, vUnit)
				end
			end
		end
	end
end
function BlanketGermination(rhealth, treehealth, rmana)
	if ccR.Player.Has.Talent(GERMINATION_TALENT) and ccR.Spell.Is.Ready(REJUVENATION) then
		for i = 1, # ccR_Friendly do 
			local vUnit = ccR_Friendly[i]
			if ccR.Unit.Exists(vUnit) and ccR.Unit.Is.Alive(vUnit) and ValidToHeal(vUnit) and (ccR.Unit.Is.APlayer(vUnit) or onlyPlayers == false) and ccR.Unit.Is.InLineOfSight(vUnit) and ccR.Unit.Distance(vUnit, "player") <= 40 then
				

				if ccR.Unit.Distance(vUnit, "player") <= 40 and ccR.Unit.Has.MyBuff(vUnit, REJUVENATION) and (not ccR.Unit.Has.MyBuff(vUnit, GERMINATION)) and (ccR.Unit.Health(vUnit) < 90 or (ccR.Player.Has.Buff(TREE_OF_LIFE) and ccR.Unit.Health(vUnit) < 80 ) or ccR.Unit.Has.Debuff(vUnit, 162184) ) then
					ccR.Cast.Spell(REJUVENATION, vUnit)
				end
			end
		end
	end
end

function GetAveragePositionOfObjects (Objects)
	local Total = #Objects;
	local X, Y, Z = 0, 0, 0;
	
	for Key, ThisObject in pairs(Objects) do
		if ThisObject then
			local ThisX, ThisY, ThisZ =  ObjectPosition(ThisObject);
			if ThisX and ThisY then
				X = X + ThisX;
				Y = Y + ThisY;
				Z = Z + ThisZ;
			end
		end
	end

	X = X / Total;
	Y = Y / Total;
	Z = Z / Total;
	return X, Y, Z;
end